<template>
  <div class="select_data_info">
    <el-select v-model="dataInfo" filterable placeholder="请选择" @change="updateDataInfo">
      <el-option
        v-for="item in options"
        :key="item.id"
        :label="item.dataName"
        :value="item.id">
      </el-option>
    </el-select>
  </div>
</template>

<script>
import { dataTypeAll } from "@/api/system/aData";

export default {
  name: "SelectDataInfo",
  model:{
    prop:'value',
    event:'updateDataInfo'
  },
  props:{
    value:{
      type: Number|String
    },
  },
  data() {
    return {
      options:[],
      dataInfo:null,
      url : '/pages/database/index?id=',
      // 查询参数
      queryParams: {
        daTitle: null
      },
    };
  },
  watch:{
    'value':{
      handler(val){
        if (val !== undefined){
          if(val != null){
            let id = val.replace(this.url,'');
            this.dataInfo = parseInt(id)
          }
        }else{
          this.dataInfo = parseInt(val)
        }
        if (isNaN(this.dataInfo)){
          this.dataInfo = null;
        }
      },
      immediate:true,
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询素材库详情列表 */
    getList() {
      dataTypeAll(this.queryParams).then(response => {
        this.options = response.data;
      });
    },
    updateDataInfo(){
      this.$emit('updateDataInfo',this.url + this.dataInfo)
    },
  }
};
</script>
